package com.fr.base.core.json;

public class JSONTokener
{
  private int myIndex = 0;
  private String mySource;

  public JSONTokener(String paramString)
  {
    this.mySource = paramString;
  }

  public void back()
  {
    if (this.myIndex > 0)
      this.myIndex -= 1;
  }

  public static int dehexchar(char paramChar)
  {
    if ((paramChar >= '0') && (paramChar <= '9'))
      return (paramChar - '0');
    if ((paramChar >= 'A') && (paramChar <= 'F'))
      return (paramChar - '7');
    if ((paramChar >= 'a') && (paramChar <= 'f'))
      return (paramChar - 'W');
    return -1;
  }

  public boolean more()
  {
    return (this.myIndex < this.mySource.length());
  }

  public char next()
  {
    if (more())
    {
      int i = this.mySource.charAt(this.myIndex);
      this.myIndex += 1;
      return i;
    }
    return ';
  }

  public char next(char paramChar)
    throws JSONException
  {
    char c = next();
    if (c != paramChar)
      throw syntaxError("Expected '" + paramChar + "' and instead saw '" + c + "'");
    return c;
  }

  public String next(int paramInt)
    throws JSONException
  {
    int i = this.myIndex;
    int j = i + paramInt;
    if (j >= this.mySource.length())
      throw syntaxError("Substring bounds error");
    this.myIndex += paramInt;
    return this.mySource.substring(i, j);
  }

  public char nextClean()
    throws JSONException
  {
    int i;
    do
      while (true)
      {
        while (true)
        {
          i = next();
          if (i != 47)
            break label112;
          switch (next())
          {
          case '/':
            do
              do
                i = next();
              while ((i == 10) || (i == 13));
            while (i != 0);
          case '*':
          }
        }
        while (true)
        {
          while (true)
          {
            do
            {
              i = next();
              if (i == 0)
                throw syntaxError("Unclosed comment");
            }
            while (i != 42);
            if (next() != '/')
              break;
          }
          back();
        }
        back();
        return '/';
        label112: if (i != 35)
          break;
        do
          do
            i = next();
          while ((i == 10) || (i == 13));
        while (i != 0);
      }
    while ((i != 0) && (i <= 32));
    return i;
  }

  public String nextString(char paramChar)
    throws JSONException
  {
    StringBuffer localStringBuffer = new StringBuffer();
    while (true)
    {
      char c;
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  while (true)
                  {
                    while (true)
                    {
                      c = next();
                      switch (c)
                      {
                      case '\0':
                      case '\n':
                      case '\r':
                        throw syntaxError("Unterminated string");
                      case '\\':
                        c = next();
                        switch (c)
                        {
                        case 'b':
                          localStringBuffer.append('\b');
                        case 't':
                        case 'n':
                        case 'f':
                        case 'r':
                        case 'u':
                        case 'x':
                        case 'c':
                        case 'd':
                        case 'e':
                        case 'g':
                        case 'h':
                        case 'i':
                        case 'j':
                        case 'k':
                        case 'l':
                        case 'm':
                        case 'o':
                        case 'p':
                        case 'q':
                        case 's':
                        case 'v':
                        case 'w':
                        }
                      }
                    }
                    localStringBuffer.append('\t');
                  }
                  localStringBuffer.append('\n');
                }
                localStringBuffer.append('\f');
              }
              localStringBuffer.append('\r');
            }
            localStringBuffer.append((char)Integer.parseInt(next(4), 16));
          }
          localStringBuffer.append((char)Integer.parseInt(next(2), 16));
        }
        localStringBuffer.append(c);
      }
      if (c == paramChar)
        return localStringBuffer.toString();
      localStringBuffer.append(c);
    }
  }

  public String nextTo(char paramChar)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    while (true)
    {
      char c = next();
      if ((c == paramChar) || (c == 0) || (c == '\n') || (c == '\r'))
      {
        if (c != 0)
          back();
        return localStringBuffer.toString().trim();
      }
      localStringBuffer.append(c);
    }
  }

  public String nextTo(String paramString)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    while (true)
    {
      char c = next();
      if ((paramString.indexOf(c) >= 0) || (c == 0) || (c == '\n') || (c == '\r'))
      {
        if (c != 0)
          back();
        return localStringBuffer.toString().trim();
      }
      localStringBuffer.append(c);
    }
  }

  public Object nextValue()
    throws JSONException
  {
    char c1 = nextClean();
    switch (c1)
    {
    case '"':
    case '\'':
      return nextString(c1);
    case '{':
      back();
      return new JSONObject(this);
    case '[':
      back();
      return new JSONArray(this);
    }
    StringBuffer localStringBuffer = new StringBuffer();
    char c2 = c1;
    while ((c1 >= ' ') && (",:]}/\\\"[{;=#".indexOf(c1) < 0))
    {
      localStringBuffer.append(c1);
      c1 = next();
    }
    back();
    String str = localStringBuffer.toString().trim();
    if (str.equals(""))
      throw syntaxError("Missing value");
    if (str.equalsIgnoreCase("true"))
      return Boolean.TRUE;
    if (str.equalsIgnoreCase("false"))
      return Boolean.FALSE;
    if (str.equalsIgnoreCase("null"))
      return JSONObject.NULL;
    if (((c2 >= '0') && (c2 <= '9')) || (c2 == '.') || (c2 == '-') || (c2 == '+'))
    {
      if ((c2 != '0') || ((str.length() > 2) && (((str.charAt(1) == 'x') || (str.charAt(1) == 'X')))));
      try
      {
        return new Integer(Integer.parseInt(str.substring(2), 16));
      }
      catch (Exception localException3)
      {
        try
        {
          return new Integer(Integer.parseInt(str, 8));
        }
        catch (Exception localException3)
        {
          try
          {
            return new Integer(str);
          }
          catch (Exception localException3)
          {
            try
            {
              return new Long(str);
            }
            catch (Exception localException4)
            {
              try
              {
                return new Double(str);
              }
              catch (Exception localException5)
              {
                return str;
              }
            }
          }
        }
      }
    }
    return str;
  }

  public char skipTo(char paramChar)
  {
    char c;
    int i = this.myIndex;
    do
    {
      c = next();
      if (c == 0)
      {
        this.myIndex = i;
        return c;
      }
    }
    while (c != paramChar);
    back();
    return c;
  }

  public boolean skipPast(String paramString)
  {
    this.myIndex = this.mySource.indexOf(paramString, this.myIndex);
    if (this.myIndex < 0)
    {
      this.myIndex = this.mySource.length();
      return false;
    }
    this.myIndex += paramString.length();
    return true;
  }

  public JSONException syntaxError(String paramString)
  {
    return new JSONException(paramString + toString());
  }

  public String toString()
  {
    return " at character " + this.myIndex + " of " + this.mySource;
  }
}